﻿package {
	import flash.display.*;
	import flash.events.*;
	import flash.text.*;
	import flash.geom.*;
	import flash.net.*;
	import flash.ui.*;
	import fl.events.*;
	import fl.data.*;
	import fl.managers.*;
	import fl.controls.*;
	import fl.controls.listClasses.*;
	import com.cenfun.ui.*;
	public final class Tree extends MovieClip {
		public static var format:TextFormat;
		public static var format_on:TextFormat;
		public static var play_id:int = 0;
		public static var play_item:Object;
		//
		public var tree:TR = new TR();
		public var data:TD;
		//
		public var keyword:TextField = new TextField();
		public function Tree():void {
			format = new TextFormat();
			format_on = new TextFormat();
			//
			tree.verticalLineScrollSize = 20;
			tree.addEventListener(Event.CHANGE, changeHandler);
			tree.setSize(320, 400);
			addChild(tree);
			//
			keyword.type = TextFieldType.INPUT;
			keyword.background = true;
			keyword.backgroundColor = 0xffffff;
			keyword.width = 200;
			keyword.height = 20;
			keyword.x = 330;
			keyword.y = 10;
			keyword.addEventListener(Event.CHANGE, keywordHandler);
			keyword.addEventListener(KeyboardEvent.KEY_UP, findHandler);
			addChild(keyword);
			//
			init();
		}
		private function init():void {
			format.align = format_on.align = "left";
			format.font = format_on.font = null;
			format.size = format_on.size = 12;
			format.color = 0xffffff;
			format_on.color = 0xff0000;
			//
			var loader:URLLoader = new URLLoader();
			loader.addEventListener(Event.COMPLETE, completeHandler);
			loader.addEventListener(IOErrorEvent.IO_ERROR, ioErrorHandler);
			var request:URLRequest = new URLRequest("list.xml");
			loader.load(request);
		}
		function completeHandler(e:Event):void {
			var xml:XML = new XML(e.target.data);
			data = new TD(xml);
			tree.dataProvider = data;
		}
		function ioErrorHandler(e:IOErrorEvent):void {
			trace("ioErrorHandler: " + e);
		}
		private function changeHandler(e:Event):void {
			play_id = tree.selectedIndex;
			play_item = tree.selectedItem;
		}
		
		function keywordHandler(e:Event):void {
			var str:String = keyword.text;
			if (! str) {
				tree.init();
			}
		}
		function findHandler(e:KeyboardEvent):void {
			var str:String = keyword.text;
			tree.find(str);
		}



	}
}